package com.dh.example.io.handler;

import com.corundumstudio.socketio.HandshakeData;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.PingListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 心跳处理器
 *
 * @author yolo
 * @date 2024/3/7 10:52
 * @mail yolo_215@163.com
 */
@Slf4j
@Component
public class HeartBeatHandler implements PingListener {

    private String getParamsFromClient(SocketIOClient client) {

        HandshakeData data = client.getHandshakeData();

        String userId = data.getSingleUrlParam("userId");
        String pageSign = data.getSingleUrlParam("pageSign");
        String token = data.getSingleUrlParam("token");
        UUID sessionId = client.getSessionId();

        return "userId:" + userId + ",pageSign:" + pageSign + ",token: " + sessionId;
    }

    @Override
    public void onPing(SocketIOClient client) {
        log.debug("客户端心跳-ping:" + getParamsFromClient(client));
    }
}
